﻿using Spring.Validation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HCQ2_Model;

namespace HCQ2_Model
{
    public class BaseAddressParam
    {
        [Required(ErrorMessage = "userid：用户内部id不能为空")]
        public string userid { get; set; }
        public int id { get; set; }
        /// <summary>
        ///  默认地址 【0=返回用户的全部收货地址（默认），1=只返回默认收货地址】
        ///  如果没有设置默认地址则返回最新设置的地址
        /// </summary>
        public int isDefault { get; set; }
    }
    /// <summary>
    ///  地址模型
    /// </summary>
    public class AddressParam: BaseAddressParam
    {
        /// <summary>
        ///  行政区域ID
        /// </summary>
        [Required]
        [RegularExpression("^([1-9][0-9]*)$", ErrorMessage = "areaID：行政区域ID必传项！")]
        public int areaID { get; set; }
        public int user_id { get; set; }
        public string user_name { get; set; }
        [Required(ErrorMessage = "phone：手机号不能为空")]
        public string phone { get; set; }
        [Required(ErrorMessage = "area：所在区域不能为空")]
        public string area { get; set; }
        [Required(ErrorMessage = "addr：详细地址不能为空")]
        public string addr { get; set; }
        public string addr_mark { get; set; }
        public bool is_default { get; set; }
        //public int create_id { get; set; }
        //public string create_name { get; set; }
        //public string create_date { get; set; }
        //public int update_id { get; set; }
        //public string update_name { get; set; }
        //public string update_date { get; set; }
        public decimal? gps_x { get; set; }
        public decimal? gps_y { get; set; }
        public T_VRAddress ToEntry()
        {
            return new T_VRAddress
            {
                user_id = this.user_id,
                user_name = this.user_name,
                phone = this.phone,
                area = this.area,
                addr = this.addr,
                addr_mark = this.addr_mark,
                is_default = this.is_default,
                //create_id = this.create_id,
                //create_date = DateTime.Now,
                //create_name = this.create_name,
                //update_id = this.update_id,
                //update_name = this.update_name,
                //update_date = DateTime.Now,
                gps_x = this.gps_x,
                gps_y = this.gps_y
            };
        }
    }
    public partial class T_VRAddress
    {
        public AddressParam ToPOCO()
        {
            return new AddressParam
            {
                id = this.id,
                user_id = this.user_id,
                user_name = this.user_name,
                phone = this.phone,
                area = this.area,
                addr = this.addr,
                addr_mark = this.addr_mark,
                is_default = this.is_default,
                //create_id = this.create_id,
                //create_date = this.create_date.ToString("yyyy-MM-dd HH:mm"),
                //create_name = this.create_name,
                //update_id = this.update_id,
                //update_name = this.update_name,
                //update_date = this.update_date.ToString("yyyy-MM-dd HH:mm"),
                gps_x = this.gps_x,
                gps_y = this.gps_y
            };
        }
    }
}